/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.List;
import java.util.Map;

import com.dian.common.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.dian.common.controller.AbstractController;
import com.dian.modules.base.entity.ClassEntity;
import com.dian.modules.base.service.ClassService;
import com.dian.common.utils.R;

/**
 * 分类表
 *
 * @author Jinag Run
 * @email 1685269193qq.com
 * @date 2019-05-22 23:47:42
 */
@RestController
@Api("分类表接口")
@RequestMapping("base/class")
public class ClassController extends AbstractController{
    @Autowired
    private ClassService baseClassService;

    /**
     * 所有菜单列表
     */
    @GetMapping("/list")
    @RequiresPermissions("base:class:list")
    public R list(){
        List<ClassEntity> baseList = baseClassService.list();
        return R.ok(baseList);
    }


    /**
     * 选择上级(添加、修改上级)
     */
    @GetMapping("/select")
    @RequiresPermissions("base:class:list")
    public R select(){
        return R.ok().put( baseClassService.selectInfo());
    }
    /**
     * 分类表信息
     */
    @SysLog("分类表信息")
    @ApiOperation("分类表信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("base:class:info")
    public R info(@PathVariable("id") Long id){
		ClassEntity baseClass = baseClassService.getById(id);
        return R.ok().put( baseClass);
    }

    /**
     * 分类表保存
     */
    @SysLog("分类表保存")
    @ApiOperation("分类表保存")
    @PostMapping("/save")
    @RequiresPermissions("base:class:save")
    public R save(@RequestBody ClassEntity baseClass){
        baseClassService.saveInfo(baseClass);
        return R.ok();
    }

    /**
     * 分类表修改
     */
    @SysLog("分类表修改")
    @ApiOperation("分类表修改")
    @PostMapping("/update")
    @RequiresPermissions("base:class:update")
    public R update(@RequestBody ClassEntity baseClass){
		baseClassService.updateInfo(baseClass);

        return R.ok();
    }

    /**
     * 分类树状
     * @param
     * @throws Exception
     */
    @SysLog("分类树状")
    @RequiresPermissions("base:class:list")
    @PostMapping("/tree")
    public R tree(@RequestParam Map<String, Object> params)  {
        return R.ok().put( baseClassService.queryTreeAll(params));
    }

    /**
     * 分类表删除
     */
    @SysLog("分类表删除")
    @ApiOperation("分类表删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("base:class:delete")
    public R delete(@PathVariable("id") Long id){
        baseClassService.deleteInfo(id);
        return R.ok();
    }
}
